package com.wut.clock.controller;

import com.wut.clock.common.api.CommonPage;
import com.wut.clock.common.api.CommonResult;
import com.wut.clock.mongo.dto.FollowParams;
import com.wut.clock.service.IFollowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * @author ZYH
 * @unit D9Lab
 * @description 关注管理
 * @date 2022/6/11 10:36
 */
@RequiredArgsConstructor
@RequestMapping("/follow")
@RestController
@Api(value="关注管理器",tags = {"关注管理器"})
public class FollowController {

    private final IFollowService followService;

    @ApiOperation("添加关注")
    @PostMapping("addFollow")
    public CommonResult<String> addFollow(@RequestBody FollowParams followParams){
        if(followService.addFollow(followParams)>0) return CommonResult.success();
        return CommonResult.failed();
    }

    @ApiOperation("取消关注")
    @PostMapping("deleteFollow/{followeeUserId}")
    public CommonResult<String> deleteFollow(@PathVariable Integer followeeUserId){
        if(followService.deleteFollow(followeeUserId) > 0) return CommonResult.success();
        return CommonResult.failed();
    }

    @ApiOperation("获取当前用户的关注列表")
    @GetMapping("getFolloweeList")
    public CommonResult<CommonPage<FollowParams>> getFolloweeList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                                  @RequestParam(defaultValue = "10") Integer pageSize){
        Page<FollowParams> followeeList = followService.getFolloweeList(pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(followeeList));
    }

    @ApiOperation("获取当前用户的粉丝列表")
    @GetMapping("getFollowerList")
    public CommonResult<CommonPage<FollowParams>> getFollowerList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                                  @RequestParam(defaultValue = "10") Integer pageSize){
        Page<FollowParams> followerList = followService.getFollowerList(pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(followerList));
    }

}
